import type { ApiOrderTypes } from "@/api/api-types/api-order-types";
import { ORDER_CHANNEL, ORDER_CHANNEL_TYPE, ORDER_CREATE_TYPE, ORDER_PAY_STATUS, ORDER_STATUS } from "@/pd-libs/enum/pd-enum";

/**
 * 是否为顺风车订单
 * @param channel 订单渠道
 * @returns {boolean} 
 */
export function isOnTheWayOrder(channel: ORDER_CHANNEL): boolean {
	return [
		ORDER_CHANNEL.pdyc,
		ORDER_CHANNEL.ykp,
		ORDER_CHANNEL.kh,
		ORDER_CHANNEL.haLuohitchRide,
		ORDER_CHANNEL.tongChenghitchRide,
		ORDER_CHANNEL.meituan
	].includes(channel);
}

/**
 * 是否为接送机订单
 */
export function isFlightOrder(channel: ORDER_CHANNEL): boolean {
	return [
		ORDER_CHANNEL.ctripBus,
		ORDER_CHANNEL.ctripFlight,
		ORDER_CHANNEL.flyPigFlight,
	].includes(channel);
}

/**
 * 是否为车队录入订单
 */
export function isCpInputOrder(createType?: ORDER_CREATE_TYPE) {
	return createType && createType === ORDER_CREATE_TYPE.cpInput;
}

/**
 * 是否为自动派单
 */
export function isAutoAssignOrder (status : ORDER_STATUS ,receive_source ?: number) {
	return Boolean(receive_source && receive_source >= 10 && status >= ORDER_STATUS.driverAccept);
}


/**
 * 订单是否需要支付才能开始行程
 */
export function isNeedPayBeforeStartOrder (order : ApiOrderTypes.OrderDto) {
	return (
		![ORDER_CHANNEL.ctripFlight, ORDER_CHANNEL.ctripBus, ORDER_CHANNEL.flyPigFlight].includes(order.channel) && order.pay_status !== ORDER_PAY_STATUS.paied && order.channel_type !== ORDER_CHANNEL_TYPE.personal
	) || (
		order.extend?.pay_node === 'schedule' && order.channel_type === ORDER_CHANNEL_TYPE.personal && order.pay_status !== ORDER_PAY_STATUS.paied
	);
}

/**
 * 是否为转卖订单
 */
export function isSaleOrder (order : ApiOrderTypes.OrderDto) {
	return order.channel === ORDER_CHANNEL.saleOrder;
}

/**
 * 是否为saas订单
 */
export function isSaasOrder (order : ApiOrderTypes.OrderDto) {
	return order && order.extend && order.extend.saas_source === 1;
}


/**
 * 是否为自动派单的订单
 */
export function isAuthDispatchOrder (order : ApiOrderTypes.OrderDto) {
	return Boolean(order && order.receive_source && order.status >= ORDER_STATUS.driverAccept && order.receive_source >= 10);
}

/**
 * 是否有im入口
 */
export function hasIm (order : ApiOrderTypes.OrderDto) {
	return [ORDER_CHANNEL.meituan, ORDER_CHANNEL.haLuohitchRide].includes(order.channel);
}